﻿using System.Collections.Specialized;
using System.Web;
//Gallio and MbUnit Framework
using MbUnit.Framework;
//MoQ Framework
using Moq;

//

namespace MockingBird.Simulator.FunctionalTests.EngineTests
{
    using MockingBird.Common.Infrastructure.Logging;
    using MockingBird.Simulator.Framework;
    using MockingBird.Simulator.Framework.Configuration;
    using MockingBird.Simulator.Framework.Interfaces;
    using MockingBird.Simulator.FunctionalTests.Common;
    //Project references
    //using MockingBird.Utilities.Context;
    using MockingBird.Simulator.Interceptors.Classic;

    [TestFixture]
    public class ClassicInterceptorFixture
    {
        private IExecutionContext context;
        private NameValueCollection headers = new NameValueCollection();


        /// <summary>
        /// This test checks if the logger has been called as soon as the classic interceptor loads up.
        /// it uses HttpSimulator to manipulate the environment and a mock logger
        /// </summary>
        [Test]
        public void ExpectCallToLoggerOnRequestInterception()
        {
            TestHelper.SetupSimulatedHttpEnvironment();
            //Setup - data
            var interceptor = new ClassicInterceptor();
            var mockLogger = new Mock<ILogger>();
            var mockDistributor = new Mock<IRequestDistributor>();
            ExecutionContext opContext = new ExecutionContext(new ApplicationConfiguration(), HttpContext.Current);

            //setup - expectations
            mockLogger.Expect(x => x.LogRequestReceived(It.IsAny<string>()));

            //Inject the mock objects using the Object attribute for MoQ artifacts
            interceptor.Logger = mockLogger.Object;
            interceptor.ExecContext = opContext;
            interceptor.Distributor = mockDistributor.Object;
            //Call the process request method.
            interceptor.ProcessRequest(HttpContext.Current);


            //verify the call to the logger
            mockLogger.Verify();
        }

    }
}
